package com.imooc.servlet.servletcontext;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 测试ServletContext - web应用全局对象
 * 页面默认首页，获取请求全局对象ServletContext，获取属性值，输出到html页面
 */
@WebServlet("/servletcontext/default")
public class ServletContextDefault extends HttpServlet {
	private static final long serialVersionUID = 1L;
       



	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletContext context = request.getServletContext();
		//获取context全局对象的属性值
		String copyright = (String) context.getAttribute("copyright");
		String title = (String) context.getAttribute("title");
		
		response.setContentType("text/html;charset=utf-8");
		//输出到Html页面
		response.getWriter().println("<h1>" + title + "</h1>" + copyright);
	}

}
